//------------------------------------------------------------------
#property copyright   "copyright mladen"
#property description "Future MACD"
#property description "made by mladen"
#property link        "mladenfx@gmail.com"
//------------------------------------------------------------------
#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1  clrSilver
#property indicator_color2  clrRed
#property strict

extern int                FastEMA      = 21;          // Fast ema
extern int                SlowEMA      = 50;          // Slow ema
extern int                Signal       = 9;           // Signal period
extern ENUM_APPLIED_PRICE Price        = PRICE_CLOSE; // MACD price
extern ENUM_MA_METHOD     SignalMethod = MODE_EMA;    // Signal method

double fmacd[],fmacds[],fake[];

//----------------------------------------------------------
//
//----------------------------------------------------------
//
//
//
//
//

int OnInit() 
{
   IndicatorDigits(6);
   SetIndexBuffer(0,fmacd);  SetIndexShift(0,FastEMA); SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(1,fmacds); SetIndexShift(1,FastEMA); SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(2,fake);   SetIndexStyle(2,DRAW_LINE,0,0,clrNONE); SetIndexLabel(2,"");
   return(INIT_SUCCEEDED);
}

//----------------------------------------------------------
//
//----------------------------------------------------------
//
//
//
//
//

int start() 
{
   int counted_bars=IndicatorCounted();
      if(counted_bars < 0) return(-1);
      if(counted_bars > 0) counted_bars--;
           int limit = MathMin(MathMax(Bars-counted_bars,FastEMA),Bars-1);

   for (int i = limit; i>=0; i--) fmacd[i]  = fake[i] = (i<FastEMA) ? iMA(NULL,0,i+1,0,MODE_EMA,Price,0)-iMA(NULL,0,i+SlowEMA-FastEMA+1,0,MODE_EMA,Price,0) : iMA(NULL,0,FastEMA,0,MODE_EMA,Price,i-FastEMA)-iMA(NULL,0,SlowEMA,0,MODE_EMA,Price,i-FastEMA);
   for (int i = limit; i>=0; i--) fmacds[i] = iMAOnArray(fmacd,0,Signal,0,SignalMethod,i);
   return (0);
}